<?php
/**
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file license.txt or that can be found at 
 * http://code.google.com/p/billboardce/wiki/License.
 *
 * @package    Slidestream_Device
 * @category   Model
 * @license    http://code.google.com/p/billboardce/wiki/License New BSD License
 * @version    SVN: $Id: $
 */
class Slidestream_Device extends Ot_Db_Table
{
    /**
     * Name of the table in the database
     *
     * @var string
     */
    protected $_name = 'tbl_slidestream_device';
  
    /**
     * Primary key of the table
     *
     * @var string
     */
    protected $_primary = 'deviceId';
    
    /**
     * Returns an array of all the devices that are assigned to a slidestream
     * 
     * @param int $slidestreamId The slide stream ID to get the entities for
     * @param bool $getDisabled Whether or not to return disabled slides
     * @return array The entities in the slide stream
     */
    public function getDevicesForSlidestream($slidestreamId) {
        
        $where = $this->getAdapter()->quoteInto('slidestreamId = ?', $slidestreamId);
        
        $result = $this->fetchAll($where);
        
        $deviceIds = array();
        foreach ($result as $r) {
            $deviceIds[] = $r->deviceId;
        }
        
        if (count($deviceIds) == 0) {
            return array();
        }
        
        $device = new Device();
        
        $where = $this->getAdapter()->quoteInto('deviceId IN(?)', $deviceIds);
        
        return $device->fetchAll($where)->toArray();
    }
    
    public function getSlidestreamForDevice($deviceId)
    {
        $thisEntry = $this->find($deviceId);
        
        if (is_null($thisEntry)) {
            return null;
        }
        
        return $thisEntry->slidestreamId;
    }
}